
#include <soko/URLDecoder.h>

URLDecoder::URLDecoder() {
	_hex2IndexMap['0'] = 0;
	_hex2IndexMap['1'] = 1;
	_hex2IndexMap['2'] = 2;
	_hex2IndexMap['3'] = 3;
	_hex2IndexMap['4'] = 4;
	_hex2IndexMap['5'] = 5;
	_hex2IndexMap['6'] = 6;
	_hex2IndexMap['7'] = 7;
	_hex2IndexMap['8'] = 8;
	_hex2IndexMap['9'] = 9;
	_hex2IndexMap['A'] = 10;
	_hex2IndexMap['B'] = 11;
	_hex2IndexMap['C'] = 12;
	_hex2IndexMap['D'] = 13;
	_hex2IndexMap['E'] = 14;
	_hex2IndexMap['F'] = 15;
}

URLDecoder & URLDecoder::operator>>(const std::wstring & string) {

	for (int i = 0; i < string.length(); ++i) {
		std::wstring::value_type c = string[i];
		if (c != '%') {
			_bytes.append(1, c);
		}
		else {
			char b = (_hex2IndexMap[string[++i]] << 4);
			b |= _hex2IndexMap[string[++i]];
			_bytes.append(1, b);
		}
	}

	return *this;
}

